//
//  CXHToBidNativeAdapter.m
//  CXHAdSDK-ToBid
//
//  Created by 陈坤 on 2025/4/4.
//

#import "CXHToBidNativeAdapter.h"
#import <WindFoundation/WindFoundation.h>
#import "CXHToBidNativeAd.h"
#import "CXHToBidNativeExpressAd.h"
#import <CXHAdSDK-Kit/CXHUtilsKit.h>

@interface CXHToBidNativeAdapter ()

@property (nonatomic, weak) id<AWMCustomNativeAdapterBridge> bridge;
@property (nonatomic, strong) id<CXHToBidAdProtocol> ad;

@end

@implementation CXHToBidNativeAdapter

- (instancetype)initWithBridge:(id<AWMCustomNativeAdapterBridge>)bridge {
    self = [super init];
    if (self) {
        _bridge = bridge;
    }
    return self;
}
- (void)loadAdWithPlacementId:(NSString *)placementId adSize:(CGSize)size parameter:(AWMParameter *)parameter {
    int isExpress;
    NSDictionary *dic = [parameter.extra CXH_objectOrNilForKey:@"m_extra"];
    if (kCXHDictIsEmpty(dic)) {
        isExpress = 1;
    }
    id expressObj = [dic CXH_objectOrNilForKey:@"isExpress"];
    if (expressObj) {
        isExpress = [expressObj intValue];
    }else {
        isExpress = 1;
    }
    if (isExpress == 1) {
        self.ad = [[CXHToBidNativeExpressAd alloc] initWithBridge:self.bridge adapter:self];
    }else {
        self.ad = [[CXHToBidNativeAd alloc] initWithBridge:self.bridge adapter:self];
    }
    [self.ad loadAdWithPlacementId:placementId adSize:size parameter:parameter];
}

- (BOOL)mediatedAdStatus{
    return true;
}

- (void)didReceiveBidResult:(AWMMediaBidResult *)result {
    [self.ad didReceiveBidResult:result];
}
- (void)dealloc {
    WindmillLogDebug(@"[cxh]", @"%s", __func__);
}

@end
